<extend name="./public/frame.html"/>
<block name="content">
    <blockquote class="layui-elem-quote search">
        <div class="layui-inline">
            开始时间：
            <div class="layui-inline">
                <input type="text" class="layui-input" id="start">
            </div>
            结束时间：
            <div class="layui-inline">
                <input type="text" class="layui-input" id="end">
            </div>
        </div>
        <div class="layui-inline">
            <input type="text" name="name" lay-verify="required|name" required placeholder="车队名称" class="layui-input" id="name">
        </div>
        <div class="layui-inline">
            <input type="text" name="user_phone" lay-verify="required|user_phone" required placeholder="用户手机号" class="layui-input" id="user_phone">
        </div>
        <div class="layui-inline">
            <select name="type" id="type" class="layui-input" lay-filter="type" style="width: 100px;">
                <option value="">全部类型</option>
                <option value="1">首次下单</option>
                <option value="2">首次登录</option>
            </select>
        </div>
        <div class="layui-inline">
            <input type="text" name="order_sn" lay-verify="required|order_sn" required placeholder="订单号" class="layui-input" id="order_sn">
        </div>
        <div class="layui-inline">
            <button class="layui-btn" id="search" data-type="search">搜索</button>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-warm" id="excel" data-type="excel">导出数据</button>
        </div>
    </blockquote>

    <table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('Business/log')}', page: true, limit: 10, id:'Business'}" lay-filter="Business">
        <thead>
        <tr>
            <th lay-data="{checkbox:true, fixed: true}"></th>
            <th lay-data="{field:'id', width:100,align:'center', fixed: true, sort: true}">流水ID</th>
            <th lay-data="{field:'name', width:200,align:'center'}">车队名称</th>
            <th lay-data="{field:'user_phone', width:150,align:'center'}">用户手机号</th>
            <th lay-data="{field:'type', width:150,align:'center'}">类型</th>
            <th lay-data="{field:'first_money', width:150,align:'center'}">首单金额</th>
            <th lay-data="{field:'order_sn', width:200,align:'center'}">订单号</th>
            <!--<th lay-data="{field:'percent_money', width:150,align:'center'}">提成金额</th>-->
            <th lay-data="{field:'create_time', width:200,align:'center'}">完成日期</th>
            <th lay-data="{field:'state', width:150,align:'center'}">支付状态</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit" style="width: 50px">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" style="width: 50px">删除</a>
    </script>
    <script>
        layui.use(['table','laydate'], function () {
            var table = layui.table;
            var laydate = layui.laydate;
            laydate.render({
                elem: '#start' //指定元素
                , type: 'datetime'
            });
            laydate.render({
                elem: '#end' //指定元素
                , type: 'datetime'
            });
            //搜索
            $('#search').on('click', function () {
                var name = $("#name").val();
                var user_phone = $('#user_phone').val();
                var order_sn = $('#order_sn').val();
                var start_time = $("#start").val();
                var end_time = $("#end").val();
                var type = $("#type").val();
                table.reload('Business', {
                    url: '/admin/Business/log', where: {
                        "name": name,
                        "user_phone": user_phone,
                        "order_sn": order_sn,
                        "start_time": start_time,
                        "end_time": end_time,
                        "type":type
                    }
                });
            })
        });

        $("#excel").on('click',function () {
            var headers = {
                'id': '流水ID',
                'name': '车队名称',
                'user_phone': '用户手机号',
                'type': '类型',
                'first_money': '首单金额',
                'order_sn': '订单号',
                'percent_money': '提成金额',
                'create_time': '完成日期',
                'state': '支付状态'
            };
            var header_str = JSON.stringify(headers);
            var name = $("#name").val();
            var user_phone = $('#user_phone').val();
            var order_sn = $('#order_sn').val();
            var start_time = $("#start").val();
            var end_time = $("#end").val();
            var type = $("#type").val();
            var str = "&name=" + name + "&user_phone=" + user_phone + "&order_sn=" + order_sn + "&start_time=" + start_time + "&end_time=" + end_time+"&type="+type;
            layer.confirm('请选择导出内容', {
                btn: ['全部数据','取消'] //可以无限个按钮
                , btn3: function (index,layero) {
                    layer.close(index);
                }
            }, function (index) {
                //按钮【按钮一】的回调
                location = "{:url('logExcel','type=1&headers=')}" + header_str + str;
                layer.close(index);
            });
        });

    </script>
</block>
